package cn.tedu.sp03.user.controller;

import cn.tedu.sp01.Util.JsonResult;
import cn.tedu.sp01.pojo.User;
import cn.tedu.sp01.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
//@RequestMapping("/user/")
public class UserController {
    @Autowired
    private UserService userService;
    //获取用户
    // http://localhost:8101/user/{userId}
    @GetMapping("/{userId}")
    public JsonResult<User> getUser(@PathVariable Integer userId){
        User user = userService.getUser(userId);
        //{code:200,msg:null,data:用户对象}
        return JsonResult.ok().data(user);
    }

    //增加用户积分
    //http://localhost:8101/user/8/score?score=100
    @GetMapping("/{userId}/score")
    public JsonResult<?> addScore(@PathVariable Integer userId,Integer score){
        userService.addScore(userId, score);
        return JsonResult.ok().msg("增加用户积分成功");
    }
}
